﻿using System.Windows;
using System.Windows.Shapes;
using System.Windows.Controls;
using SuperFrame.Charts.SeriesParts;
using System.Windows.Data;

namespace SuperFrame.Charts
{
    public class PartColumn : BaseFillPart
    {
        public double partWidth;
        public double partHeight;
        public double columnMargin;
        internal Rectangle rectPart;

        public PartColumn() { }

        private Rect column;
        public Rect Column
        {
            get { return column; }
            set { column = value; }
        }
        
        private System.Windows.Media.Brush color;
        public System.Windows.Media.Brush Color
        {
            get { return color; }
            set { color = value; }
        }

        public PartColumn(Rect column, string data, System.Windows.Media.Brush color)
        {
            this.Column = column;
            this.Data = data;
            this.Color = color;
        }

        public override UIElement CreatePart()
        {
            Rect rect = Column;
            rectPart = new Rectangle();
            rectPart.Height = rect.Height;
            rectPart.Width = rect.Width;
            rectPart.SetValue(Canvas.LeftProperty, rect.X);
            rectPart.SetValue(Canvas.TopProperty, rect.Y);
            rectPart.Fill = Color;
            rectPart.ToolTip = Data;
            //SetBindingForStrokeandStrokeThickness(rectPart);
            return rectPart;
        }

        internal TextBlock CreateTxt()
        {
            TextBlock txt = new TextBlock();
            Rect rect = Column;
            txt.HorizontalAlignment = HorizontalAlignment.Center;
            txt.SetValue(Canvas.LeftProperty, rect.X + rect.Width / 2 - Tools.GetStrFontWidth(Data + "") / 2);
            txt.SetValue(Canvas.TopProperty, rect.Y <= 20 ? 0 : rect.Y - 20);
            txt.SetBinding(TextBlock.TextProperty, new Binding("Data") { Source = this });
            txt.SetResourceReference(TextBlock.StyleProperty, "ColumnRectTxtStyle");
            return txt;
        }

        public override void Refresh()
        {
            Rect rect = Column;
            rectPart.Height = rect.Height;
            rectPart.Width = rect.Width;
            rectPart.SetValue(Canvas.LeftProperty, rect.X);
            rectPart.SetValue(Canvas.TopProperty, rect.Y);
        }
    }
}
